<template>
  <div class="home">
    <img alt="Vue logo" src="../assets/logo.png" />
    <!-- <HelloWorld msg="Welcome to Your Vue.js App" /> -->
    <!-- 登录表单 -->
    <div class="box">
      <el-form label-position="left" label-width="60px" :model="loginData">
        <el-form-item label="用户名">
          <el-input
            v-model="loginData.username"
            placeholder="请输入用户名"
          ></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input
            v-model="loginData.password"
            show-password
            placeholder="请输入密码"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button @click="loginHandler" type="primary" style="float: right"
            >登录</el-button
          >
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
// @ is an alias to /src
// import HelloWorld from "@/components/HelloWorld.vue";
import { post_json } from "../utils/request";
export default {
  name: "Home",
  data() {
    return {
      loginData: {
        username: null,
        password: null,
      },
    };
  },
  methods: {
    loginHandler() {
      post_json("/user/login", this.loginData).then((res) => {
        console.log(res.data.token);
        sessionStorage.setItem("token", res.data.token);
        // 跳转路由
        this.$router.push({ path: "/user" });
      });
    },
  },
};
</script>
<style lang="less" scoped>
.home {
  height: 600px;
}
.box {
  width: 400px;
  height: 180px;
  margin: 0 auto;
  border-radius: 5px;
  // border: 1px solid #555;
  box-shadow: 0 0 5px 5px rgba(150, 149, 149, 0.438);
  padding: 50px 20px;
}
</style>
